insert into PL_MasterType (Code, Description, CodeMode, MasterType, AccountType, CanReceiveInvoice, TaxCode, HasRestraint, RestraintCode) 
VALUES 
('AMMINIST', 'Amministratore', 2, 1, 0, 0, '', 0, ''),
('CONDOMIN', 'Condominio', 2, 0, 0, 1, '20', 1, '4' ),
('PRIVATO', 'Privato', 2, 5, 0, 1, '20', 0, ''),
('ARTIGIAN', 'Artigiano', 2, 5, 0, 1, '20', 0, ''),
('AZIENDA', 'Azienda', 2, 5, 0, 1, '20', 0, '')

insert into PL_TaxCode(Code, Description, [Percent]) 
VALUES 
('10', '10%', 10),
('20', '20%', 20),
('21', '21%', 21),
('4', '4%', 40)

ALTER TABLE AM_Counter ADD
	InvertSuffPref bit NULL
	
update AM_Counter
set InvertSuffPref = 0 where InvertSuffPref is null	

-- Cambiare la chiave di AM_Codes e AM_CodeSegment da int a nchar(8)
-- Cambiare il contatore fatture invertendo il prefisso con il suffisso

update AM_Codes
set CodeType = 'CONDOMIN' where CodeType = '0'

update AM_Codes
set CodeType = 'AMMINIST' where CodeType = '1'

update AM_Codes
set CodeType = 'AZIENDA' where CodeType = '2'

update AM_Codes
set CodeType = 'ARTIGIAN' where CodeType = '3'

update AM_Codes
set CodeType = 'PRIVATO' where CodeType = '5'

delete from AM_Codes
where CodeType = '10'

update AM_CodeSegment
set Type = 'CONDOMIN' where Type = '0'

update AM_CodeSegment
set Type = 'AMMINIST' where Type = '1'

update AM_CodeSegment
set Type = 'AZIENDA' where Type = '2'

update AM_CodeSegment
set Type = 'ARTIGIAN' where Type = '3'

update AM_CodeSegment
set Type = 'PRIVATO' where Type = '5'

delete from AM_CodeSegment
where Type = '10'

---------------- PL MASTER ---------------
Cambiare la chiave di PL_Masters  da int a nvarchar(8)

update PL_Masters
set [Type] = 'CONDOMIN' where [Type] = '0'

update PL_Masters
set [Type] = 'AMMINIST' where [Type] = '1'

update PL_Masters
set [Type] = 'AZIENDA' where [Type] = '2'

update PL_Masters
set [Type] = 'ARTIGIAN' where [Type] = '3'

update PL_Masters
set [Type] = 'PRIVATO' where [Type] = '5'


ALTER TABLE PL_Masters
ADD
	[TaxCode] [nvarchar](8) NULL,
	[HasRestraint] [bit] NULL,
	[RestraintCode] [nvarchar](8) NULL,
	[Email] [nvarchar](35) NULL

update PL_Masters
set [HasRestraint] = 1 where PL_Masters.Type = 'CONDOMIN'

update PL_Masters
set [HasRestraint] = 0 where HasRestraint is null

update PL_Masters
set Administrator = '' where Administrator is null

update PL_Masters
set [Email] = '' where [Email] is null
	
update PL_Masters
set TaxCode = 10 where Type = 'CONDOMIN'

update PL_Masters
set TaxCode = 21 where Type in ( 'AZIENDA', 'PRIVATO' )

update PL_Masters
set TaxCode = '' where TaxCode is null

update PL_Masters
set FiscalCode = '' where FiscalCode is null

update PL_Masters
set Description = '' where Description is null

update PL_Masters
set RestraintCode = 4 where HasRestraint = 1

delete from PL_Masters
where Code = ''

---------------- PL MASTER ---------------
Cambiare type e RestraintCode di PL_SalesInvoice, taxcode  da int a nvarchar(8)


ALTER TABLE PL_SalesInvoices
ADD AmountPayed decimal(9, 2) NULL

update PL_SalesInvoices
set AmountPayed = 0 where AmountPayed is null

update PL_SalesInvoices
set [Type] = 'CONDOMIN' where [Type] = '0'

update PL_SalesInvoices
set [Type] = 'AZIENDA' where [Type] = '2'

update PL_SalesInvoices
set [Type] = 'ARTIGIAN' where [Type] = '3'

update PL_SalesInvoices
set [Type] = 'PRIVATO' where [Type] = '5' or [Type] = '4'

select * from PL_SalesInvoices
where [Master] = ''

update PL_SalesInvoices
set RestraintCode = '' where RestraintCode is null

update PL_SalesInvoices
set TaxCode = '' where TaxCode = '0'

update PL_SalesInvoices
set SalesNo = RIGHT(SalesNo,2) + '/' + LEFT(SalesNo,4)

-- Cancellare InvoiceHeader e Footer


Migrazione dado
select MP_Art, mp_cat, count(*) from Prezzi
group by MP_Art, mp_cat
having count(*) > 1

delete from Prezzi
where mp_ID in (542, 897, 1222)

update T_Fattura
set TF_CondPag = 'CONSEGNA'
where TF_CondPag is null

update T_Fattura
set TF_Mezzo = 'Cedente'
where TF_Mezzo is null

update T_Fattura
set TF_OraTras = '06.00'
where TF_OraTras = '06.__'

Cambiare le qta da real a float